package com.ustc.py.practice.controller;

import com.ustc.py.practice.entity.SubmitDTO;
import com.ustc.py.practice.service.SubmitService;
import com.ustc.py.utils.R;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@Slf4j
@RequestMapping("/submit")
public class SubmitController {

    @Resource
    private SubmitService submitService;

    //前端提交的代码code，要是base64格式
    @PostMapping("/check")
    public R submit(@RequestBody SubmitDTO submitDTO) throws IOException {
            return submitService.submit(submitDTO);
    }

    /**
     * 用户提交 numpy相关的代码在线运行，代码部分code需要前端base64编码
     * @param submitDTO 此结构里的 problemId属性请不要传值 以便与算法练习区分
     * @return
     * @throws IOException
     * Jackiehan is in charge.
     */
    @PostMapping("numpy")
    public R submitNumpy(@RequestBody SubmitDTO submitDTO) throws IOException {
        return submitService.submitNumpy(submitDTO);
    }

    /**
     * 获取用户的代码提交记录
     * @param type param参数     沿用Knowledge处的type类型划分
     *             1-algorithm   获取算法题提交记录
     *             2-numpy       获取numpy学习代码提交记录
     *             ----------------------------------------
     *             其他值         获取当前用户的所有代码提交记录
     * @return
     * Jackiehan is in charge.
     */
    @GetMapping("records")
    public R getPracticeRecord(Integer type){
        return submitService.getRecords(type);
    }






}
